//删除，如果有状态字段data-field的话，修改字段，没有data-field的话直接删除行
  function delete_line(e){
      var _id = $(e).attr('data-id');
      var _url = $(e).attr('data-url');
      var _field = $(e).attr('data-field');
      var _table = $(e).attr('data-table');
      if (!_id) {
        alert('id未传入！');
        return false;
      }
      if (confirm("确认要删除？")) {
        var tr = $(e).parents('tr');
        $.ajax({
          type: "post",
          dataType: 'json',
          url: _url,
          data: {
            id: _id,
            table: _table,
            state_field:_field
          },
          success: function(res) {
            if (res.Code == 1) {
              alert('删除成功！');
              table.ajax.reload();
              return false;
            } else {
              alert('删除失败！');
              return false;
            }
          }
        });
      }
  }


//显示隐藏
  function change_status(e) {
      var _id = $(e).data('id');
      var _url = $(e).data('url');
      var _field = $(e).data('field');
      var tr = $(e).parents('tr');
      if (!_id) {
        $('.alert-warning p').html('id未传入！');
        $('.alert-warning').css('display','block');
        return false;
      }
      $.ajax({
        type: "post",
        dataType: 'json',
        url: _url,
        data: {
          id: _id,
          state_field:_field
        },
        success: function(res) {
          if (res.ok == 1) {
            $('.alert-success p').html('操作成功！');
            $('.alert-success').slideDown('fast');
            setTimeout (function() {
              $('.alert-success').slideUp('fast');
            },3000)

            //改变图标
            _this = $(e).find('.glyphicon')
            if(res.status == 1){
              _this.removeClass('glyphicon-eye-close').addClass('glyphicon-eye-open')
              // tr.fadeOut('slow');
            }else{
              _this.removeClass('glyphicon-eye-open').addClass('glyphicon-eye-close')
            }
            return false;
          } else {
            $('.alert-error p').html('操作失败，请重试');
            $('.alert-error').slideDown('fast');
            setTimeout (function() {
              $('.alert-error').slideUp('fast');
            },3000)
            location.reload();
            return false;
          }
        }
      });
  }


//推荐
  function recommend_change(e) {
      var _id = $(e).data('id');
      var _url = $(e).data('url');
      if (!_id) {
        $('.alert-warning p').html('id未传入！');
        $('.alert-warning').css('display','block');
        return false;
      }
      $.ajax({
        type: "post",
        dataType: 'json',
        url: _url,
        data: {
          id: _id
        },
        success: function(res) {
          if (res.ok == 1) {
            $('.alert-success p').html('操作成功！');
            $('.alert-success').slideDown('fast');
            setTimeout (function() {
              $('.alert-success').slideUp('fast');
            },3000)

            //改变图标
            _this = $(e).find('.glyphicon')
            if(res.status == 1){
              _this.removeClass('glyphicon-ok-circle').addClass('glyphicon-remove-circle')
            }else{
              _this.removeClass('glyphicon-remove-circle').addClass('glyphicon-ok-circle')
            }
            return false;
          } else {
            $('.alert-error p').html('操作失败，请重试');
            $('.alert-error').slideDown('fast');
            setTimeout (function() {
              $('.alert-error').slideUp('fast');
            },3000)
            location.reload();
            return false;
          }
        }
      });
  }


/**
 * grid数据转换
 */



  function sexFormat( cellvalue, options, rowObject ){  
      if (cellvalue === 1){
          return '男';
      }
      if (cellvalue === 2){
          return '女';
      }
      if (cellvalue === 0){
          return '未知';
      }
  }  

  function statusFormat( cellvalue, options, rowObject ){  
      if (cellvalue === 1){
          return '锁定';
      }
      if (cellvalue === 0){
          return '开启';
      }
  } 

  function departFormat( cellvalue, options, rowObject ){  
      $.ajax({
          type: "post",
          dataType: 'json',
          url: '/admin/admin_role_group/department',
          data: {
            id: cellvalue
          },
          success: function(res) {
            res.data;
          }
      });
  }   